package thefirst.member.model;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import thefirst.LessonBoard.model.LessonBoardVO;
import thefirst.support.model.HelpVO;
import thefirst.support.model.NoticeVO;
/**
 * StudentOfMemberDaoImpl
 * 	MemberDao를 implements한 클래스.
 *  회원들이면 공통적으로 가지고 있는 메서드를 
 *  학생회원에 맞게 overriding 을 진행.
 *  
 *  sqlSessionTemplate을 활용해 Data access.
 * @author kosta-00-30
 *
 */
@Repository
public class StudentOfMemberDaoImpl implements MemberDao {	
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public void registerMember(MemberVO mvo) throws SQLException {
		sqlSessionTemplate.insert("member.registerStudent",mvo);
	}

	@Override
	public MemberVO showMember(MemberVO mvo) throws SQLException {
		return sqlSessionTemplate.selectOne("member.showStudent", mvo);
	}
	@Override
	public int isExistId(MemberVO mvo) throws SQLException {	
		int result=sqlSessionTemplate.selectOne("member.isExistStuId",mvo);
		return result;
	}
	@Override
	public int updateName(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateStudentName", mvo);
	}

	@Override
	public int updateGender(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateStudentGender", mvo);
	}
	
	@Override
	public int updateTel(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateStudentTel", mvo);
	}

	@Override
	public int updateEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateStudentEmail", mvo);
	}

	@Override
	public int updateHoperegion(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateStudentHoperegion", mvo);
	}
	
	public int updateGrade(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateStudentGrade", mvo);
	}
	
	public int updateHopesubject(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateStudentHopesubject", mvo);
	}
	
	public int updateAddress(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateStudentAddress", mvo);
	}
	

	@Override
	public MemberVO login(MemberVO mvo) throws SQLException {
		return sqlSessionTemplate.selectOne("member.loginstudent", mvo);
	}
	/**
	 * 학생리스트를 보여주기위하여 학생회원 전체 수를 가져온다.
	 */
	@Override
	public int selectTotalMemberCount() throws SQLException {
		return sqlSessionTemplate.selectOne("member.selectTotalStudentCount");
	}

	/**
	 * 학생찾기- 학생 리스트를 가져온다.
	 */
	public List<?> getStudentListBasic(String pageNo) throws SQLException {
		return sqlSessionTemplate.selectList("member.getStudentListBasic", pageNo);
	}


	@Override
	public void withdrawalMember(MemberVO mvo) throws SQLException {
		sqlSessionTemplate.update("member.withdrawalStudent", mvo);
	}


	/**
	 * mvo로 들어온 값(name,email)으로 학생의 id를 가져온다.
	 */
	@Override
	public String findIdByNameEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.findStudentIdByNameEmail", mvo);
	}
	/**
	 * 관리자의 고객 관리를 위한 List를 호출하는 메서드
	 */
	@Override
	public List<?> getListForAdmin(String pageNo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("member.getStudentListForAdmin", pageNo);
	}

	/**
	 * 학생찾기- 지역별 tabs를 눌렀을 때 불러올 페이지
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getMemberListRegion(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectList("member.getStudentListRegion", memberSearchVO);
	}	
	
	/**
	 * 학생찾기- 과목별tabs를 눌렀을 때 불러올 페이지
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getMemberListSubject(MemberSearchVO memberSearchVO) throws SQLException{		
		return sqlSessionTemplate.selectList("member.getStudentListSubject", memberSearchVO);
	}
	
	/**
	 * 학생찾기- 학년별tabs를 눌렀을 때 불러올 페이지
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getMemberListGrade(MemberSearchVO memberSearchVO) throws SQLException{		
		return sqlSessionTemplate.selectList("member.getStudentListGrade", memberSearchVO);
	}	

	/**
	 * 페이징빈에 처리하기위한 학생리스트를 grade(고등학교1학년)/이름  data search	
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getListStudentbyGrade(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectList("member.getListStudentbyGrade", memberSearchVO);
	}

	/**
	 * 페이징빈에 처리하기위한 학생리스트를 hopesubject(희망과외과목)/이름  data search	
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getListStudentbySubject(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectList("member.getListStudentbySubject", memberSearchVO);
	}
	public int getListStudentbySubjectCount(MemberSearchVO memberSearchVO)throws SQLException{
		System.out.println(memberSearchVO.getName()+memberSearchVO.getHopesubject());
		return sqlSessionTemplate.selectOne("member.getListStudentbySubjectCount",memberSearchVO);
	}
	
	/**
	 * 페이징빈에 처리하기위한 학생리스트를 region(희망과외지역)/이름  data search	
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getListStudentbyRegion(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectList("member.getListStudentbyRegion", memberSearchVO);
	}
	/**
	 * 학생찾기-전체보기-검색조건에 맞는 data search	
	 * @param memberSearchVO
	 * @return
	 */
	public List<?> getListStudentbyTotal(MemberSearchVO memberSearchVO) {
		System.out.println("Dao:"+memberSearchVO);
		return sqlSessionTemplate.selectList("member.getListStudentbyTotal", memberSearchVO);
	}
	
	@Override
	public MemberVO findQPassByIdEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.findStudentQPassByIdEmail",mvo);
	}

	@Override
	public String findPasswordByQnAPass(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.findStudentPasswordByQnAPass",mvo);
	}

	@Override
	public List<?> getMyHelpList(MyHelpVO myHelpVO) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("member.myHelpStudentList",myHelpVO);
	}
	/**
	 * 관리자 페이지 학생 리스트 가져오기
	 * @param pageNo
	 * @return
	 * @throws SQLException
	 */
	public List<StudentVO> getStudentListOrderByName(String pageNo) throws SQLException{
		List<StudentVO> list=sqlSessionTemplate.selectList("member.getStudentListOrderByName",pageNo);
		System.out.println("dao:"+list);
		return list;
	}
	/**
	 * 관리자 페이지 학생 리스트 가져오기(가입일순)
	 * @param pageNo
	 * @return
	 * @throws SQLException
	 */
	public List<StudentVO> getStudentListOrderByDate(String pageNo) throws SQLException{
		List<StudentVO> list=sqlSessionTemplate.selectList("member.getStudentListOrderByDate",pageNo);
		System.out.println("enrolldate dao:"+list);
		return list;
	}
	/**
	 * 학생 총 인원수
	 * @return
	 * @throws SQLException
	 */
	public int totalStudentContent() throws SQLException{
		return sqlSessionTemplate.selectOne("member.totalStudentContent");
	}

	/**
	 * 학생의 id 를 받아서 학생정보를 검색한다.
	 * @param svo
	 */
	public StudentVO getStudentInfobyId(StudentVO svo) throws SQLException{
		return sqlSessionTemplate.selectOne("member.getStudentInfobyId",svo);	
	}

	
	public List<StudentVO> getStudentListForLeft() throws SQLException{
		return sqlSessionTemplate.selectList("member.getStudentListForLeft");
	}


}
